package com.zhengke.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhengke.common.dao.CommonDao;
import com.zhengke.common.object.Result;
import com.zhengke.pojo.MallSupplier;
@Service
public class MallSupplierServiceImpl implements MallSupplierService {
	/**
     * ssx
     * */
	@Autowired
	//private MallSupplierDao dao;
	private CommonDao dao;
	
	//@SuppressWarnings("unchecked")
	@Override
	public Result querySuppliers(String supplierName, String contactsPhone, String supplierStatus,int pageNum,int size) throws Exception {
		Map<String,String> param = new HashMap<String,String>();
		param.put("supplierName", supplierName);
		param.put("contactsPhone", contactsPhone);
		param.put("supplierStatus", supplierStatus);
		
		PageHelper.startPage(pageNum, size, true);
	    
		List<MallSupplier> rtnList = (List<MallSupplier>)dao.findForList("MallSupplierMapper.querySupplier", param);
		PageInfo<MallSupplier> pageInfo = new PageInfo<MallSupplier>(rtnList);
		
		Result rs = new Result();
		rs.setCode("0");
		rs.setCount(pageInfo.getTotal());
        rs.setData(rtnList);		
		return rs;
		
	}
   
	
	 /**
	  * 删除行
	  * */
	@Override
	public Result deleteSuppliers(Integer supplierId) throws Exception {
		Map<String,Integer> param = new HashMap<String,Integer>();
		param.put("supplierId", supplierId);
		
	    dao.delete("MallSupplierMapper.deleteSupplier", param);
		return null;
	}

	/**
	 * 
	 * 修改状态
	 * */
	@Override
	public Result updateSuppliers(String supplierStatus,Integer supplierId) throws Exception {
		Map<String,Object> param = new HashMap<String,Object>();
		param.put("supplierStatus", supplierStatus);
		param.put("supplierId", supplierId);
		dao.update("MallSupplierMapper.updateSupplier", param);
		return null;
	}

	/**
	 * 修改信息
	 * */
	@Override
	public Result updatesSuppliers(MallSupplier mallSupplier) throws Exception {
		Map<String,Object> param = new HashMap<String,Object>();
		param.put("supplierId", mallSupplier.getSupplierId());
		param.put("supplierName", mallSupplier.getSupplierName());
		param.put("contactsName", mallSupplier.getContactsName());
		param.put("contactsPhone", mallSupplier.getContactsPhone());
		param.put("supplierCode", mallSupplier.getSupplierCode());
		param.put("postalCode", mallSupplier.getPostalCode());
		param.put("supplierAdderss", mallSupplier.getSupplierAdderss());
		param.put("remarks", mallSupplier.getRemarks());
		param.put("supplierStatus", mallSupplier.getSupplierStatus());
		dao.update("MallSupplierMapper.updatesSupplier", param);
		return null;
	}
	
	
	/**
	 * 新增
	 * */
	@Override
	public Result addsSuppliers(MallSupplier mallSupplier) throws Exception {
		Map<String,Object> param = new HashMap<String,Object>();
		param.put("supplierName", mallSupplier.getSupplierName());
		param.put("contactsName", mallSupplier.getContactsName());
		param.put("contactsPhone", mallSupplier.getContactsPhone());
		param.put("supplierCode", mallSupplier.getSupplierCode());
		param.put("postalCode", mallSupplier.getPostalCode());
		param.put("supplierAdderss", mallSupplier.getSupplierAdderss());
		param.put("remarks", mallSupplier.getRemarks());
		param.put("createTime", mallSupplier.getCreateTime());
		param.put("supplierStatus", mallSupplier.getSupplierStatus());
		dao.save("MallSupplierMapper.add", param);
		return null;
	}

	
	 /*
     * 批量删除
     * **/
	@Override
	public Result deletesSuppliers(List<Integer> List) throws Exception {
		dao.batchDelete("MallSupplierMapper.deletesSupplier", List);
		return null;
	}


	

	


	

	

}
